import React, { Component } from 'react'
import { InputItem,Toast } from "antd-mobile"
import {withRouter} from "react-router-dom"
import axios from "../../axios/index"
import "./login.scss"

 class login extends Component {
    state={
        account:"",
        password:""
    }
    handleChange=(value) => {
        this.setState({
            account:value
        })
    }
    passwordChange=(value) => {
        this.setState({
            password:value
        })
    }
    Login = (params)=>axios.post("api/s/loginCheck",params).catch(err=>console.log(err))
    LoginClick = async (params)=>{
        let username= this.state.account;
        let password = this.state.password;
        let res = await this.Login({
            username,
            password,
        });
        console.log(res)
        if(res.status === 0){
            Toast.info("登录成功",1);
            this.props.history.push("/my")

        }else{
            Toast.info("登录失败",res.msg)
        }
    }
    
    
    render() {
        return (
            <div className="login">
                <div className="return"><span>登录中心</span></div>
                <InputItem
                    value={this.state.account}
                    onChange={this.handleChange}
                >账号</InputItem>
                <InputItem
                    value={this.state.password}
                    onChange={this.passwordChange}
                    type="password"
                    placeholder="****"
                >密码</InputItem>
                <button onClick={this.LoginClick} className="hello">登录</button>
            </div>
        )
    }
}
export default withRouter(login)
